import request from '@/utils/request' // 网络请求方法

// 文章 - 详情
const articleDetailAPI = ({ art_id }) => {
  return request({
    url: `/v1_0/articles/${art_id}`
  })
}
// 文章 - 作者关注
const authorFollowedAPI = ({ aut_id }) => {
  return request({
    url: '/v1_0/user/followings',
    method: 'POST',
    data: {
      target: aut_id
    }
  })
}
// 文章 - 取消作者关注
const authorUnFollowedAPI = ({ aut_id }) => {
  return request({
    url: `/v1_0/user/followings/${aut_id}`,
    method: 'DELETE'
  })
}
// 点赞的 API（形参中的 artId 是文章的 Id）
const addLikeAPI = ({ artId }) => {
  return request({
    url: '/v1_0/article/likings',
    data: {
      target: artId
    },
    method: 'POST'
  })
}
// 文章 - 取消点赞(不喜欢)
const articleUnLikeAPI = ({ artId }) => {
  return request({
    url: `/v1_0/article/likings/${artId}`,
    method: 'DELETE'
  })
}
// 评论 - 获取列表
// offset第一页时, 不用在params携带(axios发现值为null会自动忽略此参数)
const commentListAPI = ({ artId, offset = null, limit = 10 }) => {
  return request({
    url: '/v1_0/comments',
    params: {
      type: 'a',
      source: artId,
      offset,
      limit
    }
  })
}

// 评论 - 发布
const sendCommentAPI = ({ artId, content }) => {
  return request({
    url: '/v1_0/comments',
    method: 'POST',
    data: {
      target: artId,
      content: content
    }
  })
}
// 评论 - 喜欢
const commentLikeAPI = ({ comId }) => {
  return request({
    url: '/v1_0/comment/likings',
    method: 'POST',
    data: {
      target: comId
    }
  })
}
// 评论 - 取消喜欢 (RestFul API)
const commentUnLikeAPI = ({ comId }) => {
  return request({
    url: `/v1_0/comment/likings/${comId}`,
    method: 'DELETE'
  })
}

export {
  articleDetailAPI,
  authorFollowedAPI,
  authorUnFollowedAPI,
  addLikeAPI,
  articleUnLikeAPI,
  commentListAPI,
  sendCommentAPI,
  commentLikeAPI,
  commentUnLikeAPI
}
